Folium Demo¶
In [1]:
Copied!
import portgeo.foliumap as portgeo
import geopandas as gpd
import pandas as pd
import portgeo.foliumap as portgeo
import geopandas as gpd
import pandas as pd
In [2]:
Copied!
m = portgeo.Map()
url = "https://github.com/opengeos/datasets/releases/download/world/continents.geojson"
m.add_geojson(
url,
name="Continents",
center=(20, 0),
zoom=1,
key_on="CONTINENT",
tooltip_fields=["CONTINENT"],
tooltip_aliases=["Continent"],
style={"color": "blue", "weight": 2, "fillOpacity": 0.2},
)
m.add_layer_control()
m
m = portgeo.Map()
url = "https://github.com/opengeos/datasets/releases/download/world/continents.geojson"
m.add_geojson(
url,
name="Continents",
center=(20, 0),
zoom=1,
key_on="CONTINENT",
tooltip_fields=["CONTINENT"],
tooltip_aliases=["Continent"],
style={"color": "blue", "weight": 2, "fillOpacity": 0.2},
)
m.add_layer_control()
m
Out[2]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [3]:
Copied!
url = "https://github.com/opengeos/datasets/releases/download/us/us_states.geojson"
gdf = gpd.read_file(url)
gdf["value"] = range(len(gdf))
gdf.head()
url = "https://github.com/opengeos/datasets/releases/download/us/us_states.geojson"
gdf = gpd.read_file(url)
gdf["value"] = range(len(gdf))
gdf.head()
Out[3]:
| id | name | geometry | value | |
|---|---|---|---|---|
| 0 | AL | Alabama | MULTIPOLYGON (((-87.3593 35.00118, -85.60668 3... | 0 |
| 1 | AK | Alaska | MULTIPOLYGON (((-131.60202 55.11798, -131.5691... | 1 |
| 2 | AZ | Arizona | MULTIPOLYGON (((-109.0425 37.00026, -109.04798... | 2 |
| 3 | AR | Arkansas | MULTIPOLYGON (((-94.47384 36.50186, -90.15254 ... | 3 |
| 4 | CA | California | MULTIPOLYGON (((-123.23326 42.00619, -122.3788... | 4 |
In [4]:
Copied!
m = portgeo.Map(center=(40, -100), zoom=4)
m.add_choropleth(
gdf=gdf,
column="value",
join_col="name",
key_on="feature.properties.name",
fill_color="YlOrRd",
legend_name="US States",
tooltip_fields=["name", "value"],
tooltip_alias={"name": "State", "value": "Value"},
name="US States",
)
m
m = portgeo.Map(center=(40, -100), zoom=4)
m.add_choropleth(
gdf=gdf,
column="value",
join_col="name",
key_on="feature.properties.name",
fill_color="YlOrRd",
legend_name="US States",
tooltip_fields=["name", "value"],
tooltip_alias={"name": "State", "value": "Value"},
name="US States",
)
m
Out[4]:
Make this Notebook Trusted to load map: File -> Trust Notebook